import { http } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import { JobCategoryOption } from '@/views/position/columns';

interface JobCategoryPayload {
  name: string;
  parentId?: number;
  isActive: boolean;
}

/**
 * @description: 获取工种列表 (分页)
 */
export function getJobCategories(params: any) {
  return http.request({
    url: '/v1/admin/jobCategories',
    method: RequestEnum.GET,
    params,
  });
}

/**
 * @description: 获取一级工种列表 (用于下拉选择)
 */
export function getFirstLevelCategories(params: any) {
  return http.request<JobCategoryOption[]>({
    url: '/v1/admin/jobCategory/c1',
    method: RequestEnum.GET,
    params,
  });
}

/**
 * @description: 新增工种类别
 */
export function addJobCategory(data: JobCategoryPayload) {
  return http.request({
    url: '/v1/admin/jobCategory',
    method: RequestEnum.POST,
    data,
  });
}

/**
 * @description: 修改工种类别
 */
export function updateJobCategory(data: JobCategoryPayload) {
  return http.request({
    url: `/v1/admin/jobCategory`,
    method: RequestEnum.PUT,
    data,
  });
}

/**
 * @description: 删除工种类别
 */
export function deleteJobCategories(jobCategoryIds: number[]) {
  return http.request({
    url: '/v1/admin/jobCategory',
    method: RequestEnum.DELETE,
    data: { jobCategoryIds },
  });
}
